// 创建一个简单的迁移文件来删除article表的type字段
const fs = require('fs');
const path = require('path');

// 迁移文件内容
const migrationContent = `import { MigrationInterface, QueryRunner } from 'typeorm';

export class RemoveArticleTypeField1718758000000 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query('ALTER TABLE article DROP COLUMN type');
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    // 回滚操作
    await queryRunner.query('ALTER TABLE article ADD COLUMN type VARCHAR(255) DEFAULT \'article\'');
  }
}`;

// 创建迁移文件
const timestamp = new Date().getTime().toString().slice(0, 10);
const migrationDir = path.join(__dirname, 'src', 'migrations');
const migrationFileName = `RemoveArticleTypeField${timestamp}.ts`;

// 确保migrations目录存在
if (!fs.existsSync(migrationDir)) {
  fs.mkdirSync(migrationDir, { recursive: true });
}

// 写入迁移文件
fs.writeFileSync(path.join(migrationDir, migrationFileName), migrationContent);
console.log(`迁移文件已创建: ${migrationFileName}`);
console.log('请运行以下命令来执行迁移:');
console.log('npx typeorm migration:run -d src/data-source.ts');
